package com.stone.gateway.config;

import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

/**
 * 刷新路由
 * @author fxj
 * @date 2020/5/9
 */
@Service
public class RouteRefresher implements ApplicationEventPublisherAware {

    private ApplicationEventPublisher publisher;

    public RouteRefresher() {
    }

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.publisher = applicationEventPublisher;
    }

    /**
     * 刷新路由调用本方法
     */
    public void refreshRoutes() {
        publisher.publishEvent(new RefreshRoutesEvent(this));
    }

}